package com.wegis.demo.controller;


import com.wegis.demo.entity.Person;
import com.wegis.demo.service.IPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author slc
 * @since 2021-07-24
 */
@RestController
@CrossOrigin("*")
@RequestMapping
public class PersonController {

    @Autowired
    private IPersonService iPersonService;

    @ResponseBody
    @GetMapping("/persons")
    public Map<String, Object> getPersons() {
        return iPersonService.getPersons();
    }

    @ResponseBody
    @GetMapping("/person/{id}")
    public Map<String, Object> getPersonById(@PathVariable("id") Integer id) {
        return iPersonService.getPersonById(id);
    }

    @ResponseBody
    @PostMapping("/persons")
    public Map<String, Object> addPeson(@RequestBody Person person) {
        System.out.println(person);
        return iPersonService.addPerson(person);
    }

    @ResponseBody
    @DeleteMapping("/persons/{id}")
    public Map<String, Object> deletePesonById(@PathVariable Integer id) {
        return iPersonService.deletePersonById(id);
    }

}

